package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.query.DestinationQuery;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;

    //查询列表
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")DestinationQuery qo){
        //pageInfo === mybais====mysql
        //page---spring-data---mongodb
        //吐司
        model.addAttribute("toasts",destinationService.getToats(qo.getParentId()));
        Page<Destination> page = destinationService.query(qo);
        model.addAttribute("page",page);
        return "destination/list";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        //通过id,和hot改变数据
        destinationService.delete(id);
        return JsonResult.success();
    }

    @RequestMapping("/updateInfo")
    @ResponseBody
    public Object updateInfo(String info,String id){
        destinationService.updateInfoById(info,id);
        return JsonResult.success();
    }


}
